//
//  VisitorLoginView.swift
//  CZWeiBo06
//
//  Created by Mac on 15/8/14.
//  Copyright (c) 2015年 Mac. All rights reserved.
//

import UIKit


protocol VisitorLoginDelegate : NSObjectProtocol {
    
    //登录
    func didVisitorViewLogin()
    //注册
    func didVisitorViewRegiest()
    
}


class VisitorLoginView: UIView {

    @IBOutlet weak var scrollImageView: UIImageView!
    
    @IBOutlet weak var iconView: UIImageView!
    
    @IBOutlet weak var msgLable: UILabel!
    
    weak var delegate : VisitorLoginDelegate?
    
    @IBAction func regiest(sender: AnyObject) {
        
        delegate?.didVisitorViewRegiest()
        
        
    }
    
    @IBAction func login(sender: AnyObject) {
        
        delegate?.didVisitorViewLogin()
    }
    
    
    func userInfo(imageName : String,message : String,isHome : Bool = false){
        
        if isHome == true {
            
            self.iconView.hidden = false
            self.iconView.image = UIImage(named: imageName)
            
            startAnimaton()
            
            
        }else {
            
            self.iconView.hidden = true
            self.scrollImageView.image = UIImage(named: imageName)
        }
        
        self.msgLable.text = message
        
        
    }
    
    
    func startAnimaton() {
        
        let main = CABasicAnimation(keyPath: "transform.rotation")
        
        main.repeatCount = MAXFLOAT
        main.duration = 20.0
        main.toValue = 2 * M_PI
        
        self.scrollImageView.layer.addAnimation(main, forKey: "RotationKey")
    }
    
    func stopAnimation() {
        
        self.scrollImageView.layer.removeAllAnimations()
    }
    
    
}
